package cn.itcasa.web;

import cn.itcasa.pojo.ItemDoc;
import cn.itcasa.pojo.RequestParams;
import cn.itcasa.service.SearchService;
import com.hmall.common.dto.PageDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/search")
@Api(value = "搜索接口")
public class SearchController {
    @Autowired
    private SearchService searchService;

    @ApiOperation(value = "搜索接口", notes = "获取相关分类信息，自动补全接口")
    @GetMapping("/suggestion")
    public List<String> getSuggestion(@RequestParam("key") String prefix) {
        log.info("前缀：{}", prefix);
        return searchService.getSuggestion(prefix);
    }

    @PostMapping("/filters")
    @ApiOperation(value = "聚合条件查询", notes = "组合查询")
    public Map<String, List<String>> search(@RequestBody RequestParams params) {
        log.info("请求参数：{}", params);
        return searchService.search(params);
    }

    @PostMapping("/list")
    @ApiOperation(value = "基本查询", notes = "排序，分页，高亮")
    public PageDTO<ItemDoc>searchAll(@RequestBody RequestParams params) {
        log.info("请求参数：{}", params);
        return searchService.searchAll(params);

    }
}
